package com.hsd.znsh.utils;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.hsd.znsh.pojo.output.FarmVO;
import org.apache.poi.ss.usermodel.Workbook;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/*
 * @auther: wangjiacai
 *
 * @create: 2018-05-03 15:12:35
 */
public class ExcelUtil {

    public static <T> void downLoadXls(String fileName, String title,String sheetName,
                                       List<T> list, Class<T> tClass, HttpServletResponse response) throws IOException {
        response.setHeader("Content-Disposition", "attachment;filename="+new String(fileName.getBytes("utf-8"),"iso8859-1"));
        response.setHeader("Content-Type", "application/octet-stream");
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(title,sheetName),
                tClass, list);
        workbook.write(response.getOutputStream());
    }
}
